package com.cn.boot.spring.controller;

import com.cn.boot.spring.entity.LimitsEntity;
import com.cn.boot.spring.entity.UserEntity;
import com.cn.boot.spring.service.ILimitsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "权限管理")
@RequestMapping("/admin/limits")
public class LimitsController {
    @Autowired
    private ILimitsService iLimitsService;
    @ApiOperation("权限列表")
    @GetMapping("/findAll")
    public List<LimitsEntity> findAll(){
        return iLimitsService.findAll();
    }
    @ApiOperation("根据id查询权限明细")
    @GetMapping("/findById1")
    public LimitsEntity findById1(@RequestParam Integer id) {
        return iLimitsService.findById(id);
    }
    @ApiOperation("根据id查询权限明细")
    @GetMapping("/findById2/{id}")
    public LimitsEntity findById2(@PathVariable Integer id) {
        return iLimitsService.findById(id);
    }


    /**
     * 添加一条数据
     * Post请求要设置请求方法，参数注解要用@RequestBody
     */
    @ApiOperation("添加一条数据")
    @PostMapping("/add")
    public Integer add(@RequestBody LimitsEntity limitsEntity) {
        return iLimitsService.add(limitsEntity);
    }

    /**
     * 批量添加
     * 参数传入list
     */
    @ApiOperation("批量添加数据")
    @PostMapping("/addLimits")
    public Integer addLimits(@RequestBody List<LimitsEntity> limits) {
        iLimitsService.addLimits(limits);
//        System.out.println(users);
        //添加几条就返回几条
        return limits.size();
    }

    /**
     * 批量删除
     */
    @ApiOperation("批量删除数据")
    @DeleteMapping("/del")
    public Integer del(@RequestBody List<Integer> ids) {
        iLimitsService.del(ids);
        //删除几条就返回几条
        return ids.size();
    }
    /**
     * 更新
     */
    @ApiOperation("更新数据")
    @PostMapping("/update")
    public Integer update(@RequestBody LimitsEntity limitsEntity){
        return iLimitsService.update(limitsEntity);
    }
}
